{{define "Title"}}图书{{end}}
{{define "Content"}}
    <p><a href="/admin/book/new" class="ui green icon button"><i class="add icon"></i> 添加</a></p>
    <table class="ui table segment">
    <thead>
        <tr>
            <th>书名</th>
            <th>封面</th>
            <th>作者</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
    {{range .books}}
        <tr id="book-{{.Id_.Hex}}">
            <td>{{.Title}}</td>
            <td><img src="http://77fkk5.com1.z0.glb.clouddn.com/static/img/{{.Cover}}-book"></td>
            <td>{{.Author}}</td>
            <td>
                <a href="/admin/book/{{.Id_.Hex}}/edit" class="ui mini icon button" title="编辑"><i class="edit icon"></i></a>
                <a book_id="{{.Id_.Hex}}" href="javascript:;" class="ui mini icon button" title="删除"><i class="remove icon"></i></a>
            </td>
        </tr>
    {{end}}
    </tbody>
    </table>

	<script type="text/javascript">
		$("a.remove-book").click(function () {
			if (confirm("确定删除吗？")) {
				var id = $(this).attr("book_id");
				$.getJSON('/admin/book/' + id +'/delete', function(data) {
					if (data) {
						$("tr#book-" + id).fadeOut("slow", function () {
							$("tr#book-" + id).remove();
						});
					};
				});
			}
		});
	</script>
{{end}}
